
$(document).ready(function () {	
	findPlanNoReportById();
	$('#relPlanBtn').click(function () {
		releasePlan();
	});
});

function releasePlan(){	
	var timestamp = Date.parse(new Date());
	$.get("lzm/Plan_releasePlan.action?ts="+timestamp+"&PId="+getCookie(PId),null,releasePlanRst);
}

function releasePlanRst(data){
	if(data.ajaxRst==SUCCESS){
		operateSucc("find_plan_pre_record.jsp");
	}else{
		alert("发布预案失败");
	}
}

function findPlanNoReportById(){	
	var timestamp = Date.parse(new Date());
	$.get("lzm/Plan_findPlanById.action?ts="+timestamp+"&PId="+getCookie(PId),null,findPlanNoReportByIdRst);
} 

function findPlanNoReportByIdRst(data){
	var plan=data.tbPlan;
	$('#PName').text(plan.PName);
	$('#planType').text(plan.tbPlanType.ptName);
	$('#planGrade').text(plan.tbPlanGrade.pgName);
	$('#eventType').text(plan.tbEventType.etEventType);
	$('#planScope').text(plan.tbPlanScope.psName);
	$('#planRegion').text(plan.tbPlanRegion.prName);
	$('#PSummary').text(plan.PSummary);
	$('#PUnit').text(plan.PUnit);
	$('#PContractor').text(plan.PContractor);
	$('#PTime').text(plan.PTime.replace(/T/," "));
	$('#PVersion').text(plan.PVersion);	
}

/**
 * 作增加预案
 */
function savePlan(){
	var url = 'lzm/SavePlan_savePlan.action';
	var params = {
			'plan.PName':$('#PName').attr('value'),
			'plan.tbPlanType.ptId':$('#planType').attr('value'),
			'plan.tbPlanGrade.pgId':$('#planGrade').attr('value'),
			'plan.tbEventType.etId':$('#eventType').attr('value'),
			'plan.tbPlanScope.psId':$('#planScope').attr('value'),
			'plan.tbPlanRegion.prId':$('#planRegion').attr('value'),
			'plan.PSummary':$('#PSummary').attr('value'),
			'plan.PUnit':$('#PUnit').attr('value'),
			'plan.PContractor':$('#PContractor').attr('value'),
			'plan.PTime':$('#PTime').attr('value'),
			'plan.PVersion':$('#PVersion').attr('value')
	}; 
	jQuery.post(url, params, savePlanRst, 'json');
}

/**
 * 作增加预案回调函数
 */
function savePlanRst(data){
	alert("gggg");
	alert(data.ajaxRst);
}